import modules from './modules'
import Vue from 'vue'
import $store from '@/utils/store/index'
import Router from 'uni-simple-router'
Vue.use(Router)
//初始化
const router = new Router({
    encodeURI:false,
    h5:{
        loading: true,
        replaceStyle:true,
    },
    routes: [...modules]//路由表
});

//全局路由前置守卫  --全局拦截需要登录的窗口
router.beforeEach((to, from, next) => {
    console.log(to)
    switch (to.name){
        default:
            if(to.requiresAuth==true && $store.getters.hasLogin!=true){
                console.log(111)
                uni.showModal({
                    title: '提示',content: '您还未登录,是否前往登录？',
                    success: function (res) {
                        if (res.confirm){ next({name: 'login_login',NAVTYPE: 'push' })}else{ next(false) }
                    }
                });
            }else{
                next()
            }
            break;
    }
})
// 全局路由后置守卫
router.afterEach((to, from) => {

})
export default router;